<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>
</head>

<body>
    <div id="app"></div>
    <script type="text/babel">

    const courses = [{id: 1, name: 'React'},{id: 3, name: 'Vue'},{id: 5, name: '小程序'},{id: 6, name: 'xxx'}]
    // 根据数据的数组生成标签的数组
    const lis=courses.map(course => <li key = {course.id} >{course.name}</li>)
    const vDom = (
        <div>
            <h2>前端框架列表</h2>
            <ul>
                {
                /*  [
                        <li key={courses[0].id}>{courses[0].name}</li>,
                        <li key={courses[1].id}>{courses[1].name}</li>,
                        <li key={courses[2].id}>{courses[2].name}</li>,
                        <li key={courses[3].id}>{courses[3].name}</li>,
                    ] 
                */
                // 根据数据的数组生成标签的数组
                // courses.map(course => <li key = {course.id}>{course.name}</li>)
                lis
            }    
            </ul>    
        </div>
    )

    /* 
        错误: Warning: Each child in a list should have a unique "key" prop

        React要求列表中的每个元素都需要有个唯一的key值 ==> 内部优化
        key值尽量用id值, 不要用下标  
    */
    /*渲染虚拟DOM */
    ReactDOM.render(vDom,document.getElementById('app'))
    </script>
</body>

</html>